package net.hn.hnms.biz.plan.vo;

import lombok.Data;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Data
public class RankScore{

    public RankScore(String key, Integer score, Integer priority) {
        this.key = key;
        this.score = score;
        this.priority = priority;
    }

    private String key;

    private Integer score;

    private Integer priority;


    public static List<RankScore> orderAsc(List<RankScore> scores) {

        Collections.sort(scores, new Comparator<RankScore>() {
            @Override
            public int compare(RankScore o1, RankScore o2) {
                if (o1.getScore() < o2.getScore()) {
                    return -1;
                } else if (o1.getScore() > o2.getScore()) {
                    return 1;
                }else{
                    if (o1.getPriority() < o2.getPriority()) {
                        return -1;
                    } else if (o1.getPriority() > o2.getPriority()) {
                        return 1;
                    }else{
                        return 0;
                    }
                }
            }
        });
        return scores;
    }


    public static List<RankScore> orderDesc(List<RankScore> scores) {
        List<RankScore> ordered = orderAsc(scores);
        Collections.reverse(ordered);
        return ordered;
    }

}
